<!--
  3.业主代表审查进度计划
-->

<template>
  <my-dialog>
    <my-header slot="header"
               :project-sub-text="dialogTitle"  project-sub-title="施工单位上报"  :project-name="project.project_name"></my-header>
    <div slot="body">
      <widgets title="标段名称" :value="project.sction_name" icon="section"></widgets>
      <widgets title="合同工期" :value="project.contract_time" icon="contract"></widgets>
      <widgets title="施工单位" :value="project.construction_organeation" icon="organization"></widgets>
      <widgets title="项目负责人" :value="project.project_manager" icon="responsibility"></widgets>
      <div style="width: 100%;display: block;height: 50px;float: left;clear: both;line-height: 50px;font-size: 20px;margin-bottom:15px;">施工单位进度图</div>
      <chart :read-only="true" :project="[]"></chart>
      <down></down>
    </div>
  </my-dialog>
</template>
<script>
  import Dialog from "@/components/Dialog";
  import Header from "@/components/Dialog/Header";
  import Widgets from "@/components/Dialog/Widgets";
  import Chart from "@/components/Dialog/Chart";
  import Down from "@/components/Dialog/Down";

  export default{
    name:"AuditPjtPgs",
    components:{
      'MyDialog':Dialog,
      'MyHeader':Header,
      Widgets,
      Chart,
      Down
    },
    data(){
      return {
        dialogTitle:"",
        chartProjectData:[],
        project:{
          project_name:"",
          sction_name:"",
          contract_time:"",
          construction_organeation:"",
          jianli_company:"",
          jianli_name:"",
          project_manager:"",
          file:[]
        }
      };
    },
    created(){
      this.projectId=this.$route.params.projectId;

      var taskId=this.$route.params.taskId;

      this.$store.dispatch('getProgressPlan',{
        'token':this.user.token,
        'pId':this.projectId,
        'taskId':taskId
      }).then((res) => {

        this.dialogTitle=res.data['0'].name;

        var project = res.data['0'].project;

        var branch_project=res.data['0'].branch_project;

        /**
         * 拷贝project的内容
         */
        for (var key in this.project){

          if (this.project.hasOwnProperty(key)&&key!='file'){

            this.project[key]=project[key];

          }

          if (key=='file'){

            for (var i=0;i<project.file.length;i++){
              this.project.file.push(project[i]);
            }

          }
        }

        for(var i=0;i<branch_project.length;i++){

          var tempObj = {
            projectName:"",
            items:[]
          };

          var primary=branch_project[i];

          tempObj.projectName=primary.branch_project_name;

          for (var j=0;j<primary.branch_son_project.length;j++){


            var tempSubObj={
              subName:"",
              startDate:'',
              endDate:''
            };

            var secondary=primary.branch_son_project[j];

            tempSubObj.subName=secondary.branch_son_project_name;
            tempSubObj.startDate=secondary.construction_begin_at;
            tempSubObj.endDate=secondary.construction_end_at;

            tempObj.items.push(tempSubObj);

          }

          this.chartProjectData.push(tempObj);

        }

      },message => {

        this.$message('错误，请求数据失败,错误信息:'+message);

        this.$router.go(-1);

      }).catch(err=>{

        this.$message('系统错误，请求数据失败，错误信息:'+err);

        this.$router.go(-1);

      });
    },
    methods:{

    }
  }
</script>
